using System;
using Synapse.Framework.Notifier;
using Synapse.Framework.Pipe.BusinessObjects;
using Synapse.Framework.Pipe.Operations;

namespace Synapse.Framework.Pipe.Filters
{
    public class Filter<TInput, TOutput> : IFilter
    {
        private readonly IOperation<TInput, TOutput> operation;
        private readonly INotifier notifier;

        public Filter(IOperation<TInput,TOutput> operation, INotifier notifier)
        {
            this.operation = operation;
            this.notifier = notifier;
        }

        public IBusinessObject Execute(IBusinessObject input)
        {
            try
            {
                return operation.Process(((BusinessObjet<TInput>) input));
            }
            catch (Exception ex)
            {
                notifier.Notify(ex);
                return new BlockObject();
            }
        }
    }
}